package cn.dev.mybatis.handler.result;

import cn.dev.mybatis.handler.ResultHandler;

import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.Map;

public abstract class AbstractResultHandler<T> implements ResultHandler<T> {

    public Map<String, Object> parseForMap(ResultSet rs, int colum) throws SQLException {
        HashMap<String, Object> resultMap = new HashMap<>();
        ResultSetMetaData metaData = rs.getMetaData();
        for (int i = 0; i < colum; i++) {
            resultMap.put(metaData.getColumnName(i + 1), rs.getObject(i + 1));
        }
        return resultMap;
    }
}
